import { createRouter, createWebHashHistory } from 'vue-router'
import qyh_router from './qyh-router';
import zz_router from './zz-router';
import zzy_router from './zzy-router';
import { useUserStore } from '../store/user'
const router = createRouter({
    history: createWebHashHistory(),//启用哈希路由模式
    routes: [
        ...qyh_router,
        ...zz_router,
        ...zzy_router
    ]
});
//路由守卫，判断是否登录
router.beforeEach((to, from, next) => {
    const user = useUserStore();
    console.log(to, from);
    //设置全局的路由守卫
    //外卖点餐、食堂点餐、积分商城、优惠券、mine未登录拦截
    if (to.path == "/wallet" || to.path == "/mine" || to.path == "/orderdel" || to.path == "/menu") {
        if (!localStorage.userInfo) {
            next("/login"); //未登录
        } else {
            next(); //已登陆
        }
        return;
    }
    next(); //不需要拦截的路由，直放行
});
export default router;